<?php

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller as LumenController;
use App\Libs\Commons\MyMessage;

class AdminBaseController extends LumenController
{
	protected $wxuid = 0;
	protected $nickname = '';

	public function __construct()
	{
	}

	public function success($data = [])
    {

        return response()->json([
            'code' =>  MyMessage::SUCCESS,
            'msg' => MyMessage::getMessage(MyMessage::SUCCESS),
            'data' => $data ?? [],
        ]);
    }

    public function fail($code = '', $msg = '')
    {
        return response()->json([
            'code' => $code ? $code : MyMessage::ERROR,
            'msg' => $msg ? $msg : MyMessage::getMessage($code),
            'data' => [],
        ]);
    }

    protected function returnJson($data = '')
    {
        $rt = [
            'code' => MyMessage::SUCCESS,
            'msg'  => MyMessage::getMessage(MyMessage::SUCCESS)
        ];
        $rt = array_merge($rt, $data);
        return response()->json($rt);
    }
}
